package com.web.mqtt.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.web.common.iot.mqtt.api.MqttUserApi;
import com.web.common.iot.mqtt.entity.MqttUser;
import com.web.common.iot.mqtt.entity.MqttUserEntity;
import com.web.common.result.R;
import com.web.mqtt.entity.MqttUserExport;
import com.web.mqtt.service.impl.MqttUserServiceImpl;
import com.web.service.handler.excel.ExportExcel;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhouhui
 * @since 2024-02-22
 */
@Tag(name = "MQTT客户端用户")
@Controller
@RequestMapping("/iot/mqttUser")
public class MqttUserController implements MqttUserApi {
	
	@Autowired
	private MqttUserServiceImpl mqttUserServiceImpl;

	@Operation(summary = "获取查询数据列表")
	@Override
	public R<IPage<MqttUserEntity>> getList(MqttUserEntity condition) {
		return mqttUserServiceImpl.getList(condition);
	}
	
	@Operation(summary = "保存数据信息")
	@Override
	public R<Object> saveInfo(MqttUser mqttUser) {
		return mqttUserServiceImpl.saveInfo(mqttUser);
	}
	
	@Operation(summary = "更新数据信息")
	@Override
	public R<Object> updateInfo(MqttUser mqttUser) {
		if(mqttUser.getMainId() == null) {
			return R.fail(null, "未选择需要更新的客户端信息");
		}
		return mqttUserServiceImpl.updateInfo(mqttUser);
	}
	
	@Operation(summary = "删除数据信息")
	@Override
	public R<Object> deleteInfo(MqttUser mqttUser) {
		if(mqttUser.getMainId() == null) {
			return R.fail(null, "未选择需要删除的客户端信息");
		}
		return mqttUserServiceImpl.deleteInfo(mqttUser);
	}

	@Operation(summary = "重置客户端密码")
	@Override
	public R<MqttUser> resetPassword(MqttUser mqttUser) {
		if(mqttUser.getMainId() == null) {
			return R.fail(null, "未选择需要重置密码的客户端");
		}
		return mqttUserServiceImpl.resetPassword(mqttUser);
	}
	
	@Operation(summary = "mqtt客户端信息导出")
	@ExportExcel(fileName = "mqttUser")
	@PostMapping(path = "/list/export")
	public List<MqttUserExport> exportMqttUser(@RequestBody MqttUser mqttUser){
		return mqttUserServiceImpl.exportMqttUser(mqttUser);
	}
}
